package com.shanwen.shopping.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanwen.shopping.R;
import com.shanwen.shopping.entity.GoodsInfo;
import com.shanwen.shopping.utils.Utils;

import java.util.List;

/**
 * Created by lex on 2017/10/12.
 */

public class ConfirmOrderListAdapter extends BaseAdapter {

    private Context context;
    private List<GoodsInfo> list;

    public ConfirmOrderListAdapter(Context context,List<GoodsInfo> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {
        ViewHolder holder = null;
        if (v==null){
            holder = new ViewHolder();
            v = LayoutInflater.from(context).inflate(R.layout.item_confirm_order,null);
            holder.tvConfirmGoodsName = (TextView) v.findViewById(R.id.tvConfirmGoodsName);
            holder.tvConfirmGoodsNum = (TextView) v.findViewById(R.id.tvConfirmGoodsNum);
            holder.tvConfirmGoodsPrice = (TextView) v.findViewById(R.id.tvConfirmGoodsPrice);
            v.setTag(holder);
        }else{
            holder = (ViewHolder) v.getTag();
        }
        holder.tvConfirmGoodsName.setText(list.get(position).getTitle());
        holder.tvConfirmGoodsNum.setText("x"+list.get(position).getNum());
        holder.tvConfirmGoodsPrice.setText(Utils.formatPrice((list.get(position).getNum()*list.get(position).getSalePrice())));
        return v;
    }

    class ViewHolder{
        TextView tvConfirmGoodsName;
        TextView tvConfirmGoodsNum;
        TextView tvConfirmGoodsPrice;
    }
}
